<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<meta http-equiv="Content-Type" content=
"text/html; charset=iso-8859-1">
<link rel='stylesheet' href='../rurple.css' type='text/css'>
<title>A Robotic Fairy Tale</title>
</head>
<body>


<h2 class="title">A Robotic Fairy Tale</h2>

<p>A long, long time ago... in a faraway land ...<br />
Are you brave enough to accept the challenge of writing function definitions that will make the following story come to life, and reproduce the final scene illustrated below?<br />
<i>Hint:</i> my solution requires only five Python keywords: 
<span class="pykeyword">def</span>, <span class="pykeyword">while</span>,
<span class="pykeyword">for</span>, <span class="pykeyword">in</span>, and <span class="pykeyword">global</span>.  You can do it of course without using
some of these keywords, but your program will be longer.</p>

<pre>
<span class="comment"># A robotic fairy tale
#
# Your definitions go here.
#</span>

<span class="comment">'''A long time ago, in RobotLand, lived a
young Robot Scholar, named Alex.'''</span>
Alex = RefurbishedRobot(1, 1, beepers=2, colour=<span class="string">'blue'</span>)

<span class="comment">'''Unhappy, the young Scholar was spending his days 
wandering around his parents' domain, hoping to find more to learn.'''</span>
Alex.set_trace_style(2, <span class="string">'black'</span>)    <span class="comment"># unhappy</span>
Alex_is_restless()

<span class="comment">'''Soon, the young Scholar set out to explore
the world, travelling far and wide. Even as he started out,
his mood brightened considerably.'''</span>
Alex.set_trace_style(1, <span class="string">'blue'</span>) 
Alex_travels()

<span class="comment">'''One day, as he entered a foreign land,
the young Scholar heard an unusual noise that made him stop.
His heart did the same when a fearless Warrior, 
named Anna, appeared seemingly out of nowhere.
She had come investigate news that 
a stranger had come to her land.'''</span>
Anna = RefurbishedRobot(4, 7, 's'</span>, colour=<span class="string">'purple'</span>)
Anna.set_trace_style(2, <span class="string">'red'</span>)

<span class="comment">'''The Scholar knew that his quest was over; 
no further did he need to search.  Approaching
the Warrior, he took out the one and only Ring, 
which he happened to carry, 
and asked Anna if she would marry him.'''</span>
Alex_proposes_and_wait()

<span class="comment">'''The Scholar's erudite use of magical words
were such that, much to Alex's delight, Anna
took the Ring he had offered her.'''</span>
Anna_accepts()
<span class="comment"># Historical note: the imprint of the Ring
# can still be seen in RobotLand where Alex proposed to Anna,
# as shown below.
# It has also been confirmed that, from that day, 
# Anna always wore her Ring.</span>

<span class="comment">'''The young couple celebrated their happiness,
and danced all day and all night.'''</span>
Alex_and_Anna_dance()

<span class="comment">'''Years went by.  Alex and Anna were happy
traveling together, side by side.'''</span>
time_passes()

<span class="comment">'''A few years later, young Alexina was born.'''</span>
Alexina_is_born()

<span class="comment">'''For many years afterwards, the happy family
pursued their travels to the edge of Robotland.'''</span>
family_is_happy()

<span class="comment">'''The End.'''</span>
Alex.turn_off()
</pre>

<p><img alt="Fairy tale, final scene" src="../../images/future/fairy_tale.png"></p>


<h3 class='section'>For further reading</h3>

<p>At this point in your Python learning journey, you might be ready to read other, more advanced material. If you feel brave, here are two suggestions which are perhaps a bit advanced but are two of my favourite Python books:</p>
<ul>
<li><i>Python in a Nutshell</i>, written by Alex Martelli, who is famous, amongst other things, for his many contributions on comp.lang.python.  His <b>many</b> insightful messages have contributed to him being known as "the martellibot".  (Other famous "bots" are "the timbot" and "the effbot".  For many years, rumours were floating that no humans could write so many messages so quickly; they had to share some characteristics with robots.)</li>
<li>Alex has also been a co-author of both the first and the second editions of the <i>Python Cookbook</i>, which I also recommend heartily.  David Ascher has been co-author of both editions of the <i>Python Cookbook</i>.  Anna Martelli Ravenscroft, Alex's wife, is a co-author of the second edition.</li>
</ul>

<h3 class="warning">Disclaimer</h3>

<p>Any resemblance between RobotLand's Scholar Alex and the Warrior Anna,
and any real-life individuals is purely coincidental.</p>

<center>
<a href="../lessons_toc.htm"><img alt="home"  src="../../images/home.png"></a>
</center>
</body>
</html>